package com.oocl.homework.crm.command;

import com.oocl.homework.crm.datastruct.Executeable;
import com.oocl.homework.crm.model.Filterable;
import com.oocl.homework.crm.model.Result;

public class LookCommand<T> extends Command<T>{
		
	
	public LookCommand(String command) {
		super(command);
	}

	@Override
	public void filter(Filterable filterable) {
		
		if(result.getCode()==-1){
			return ;
		}else{
			//带参数时验证
			if(command.length()>2){
				if(command.split(" ").length>2){
					result.setCode(-1);
					result.setMessage("Unrecognized command:"+command);
					return;
				}
				
				splitCommandParameterAttributes();
				if(result.getCode()==-1){
					return ;
				}
				Result filterResult = filterable.filter(getCommandParameterAttributes());
				if (filterResult.getCode()==-1) {
					result =  filterResult;
					return;
				}
			}
			
		}
		
	}

	@Override
	public void executeCommand(Executeable<T> executeable,T t) {
		super.executeCommand(executeable, t);
		System.out.println(executeable.search(t));
		
	}
	
	@Override
	public void display() {
		super.display();
		CommandDoc.printLookCommandHelp();
		
	}

	
}
